from django.test import TestCase
from model_mommy import mommy

from users.models import CCUser
from website.models import Artist, Album, Song, artist_path, album_path, song_path

class UserModelTests(TestCase):
    def test_user_creation(self):
        u = mommy.make(CCUser)
        self.assertTrue(isinstance(u, CCUser))
        self.assertEqual(u.__str__(), u.email)


class WebsiteModelTests(TestCase):
    def setUp(self):
        self.artist = mommy.make(Artist)
        self.album = mommy.make(Album)
        self.song = mommy.make(Song)
        self.filename = 'filename.ogg'


    def tearDown(self):
        del self.artist
        del self.album
        del self.song


    def test_artist_creation(self):
        self.assertTrue(isinstance(self.artist, Artist))
        self.assertEqual(self.artist.__str__(), self.artist.name)


    def test_artist_path(self):
        self.assertEqual(artist_path(self, self.filename), 'music/{0}/{1}'.format(self.artist.handle, self.filename))


    def test_album_creation(self):
        self.assertTrue(isinstance(self.album, Album))
        self.assertEqual(self.album.__str__(), self.album.artist.name + ' - ' + self.album.title)


    def test_album_path(self):
        self.assertEqual(album_path(self, self.filename), 'music/{0}/{1}/{2}'.format(self.album.artist.handle, self.album.title, self.filename))


    def test_song_creation(self):
        self.assertTrue(isinstance(self.song, Song))
        self.assertEqual(self.song.__str__(), self.song.artist.name + ' - ' + self.song.title + ' (' + self.song.album.title + ')')


    def test_song_path(self):
        self.assertEqual(song_path(self, self.filename), 'music/{0}/{1}/{2}'.format(self.song.artist.handle, self.song.album.title, self.filename))

